package com.jp.knowledge.my.activity;

import android.support.v4.view.ViewPager;
import android.view.View;
import android.widget.RadioGroup;

import com.jp.knowledge.R;
import com.jp.knowledge.comm.SlidingActivity;
import com.jp.knowledge.activity.BaseFragment;
import com.jp.knowledge.my.adapter.BaseFraAdapter;
import com.jp.knowledge.my.fragment.PcImportFragment;

import org.xutils.view.annotation.Event;
import org.xutils.view.annotation.ViewInject;

import java.util.ArrayList;
import java.util.List;

/**
 * 电脑端导入
 *
 * @author gzejia 978862664@qq.com
 */
public class PcImportActivity extends SlidingActivity {

    @ViewInject(R.id.pc_import_vp)
    private ViewPager mViewPager;

    @ViewInject(R.id.pc_import_rg)
    private RadioGroup mGuideGp;

    @Override
    protected int getResourceId() {
        return R.layout.activity_pc_import;
    }

    @Override
    protected void init() {
        initTitle();
        initBGABanner();
    }

    @Event(value = {R.id.icon_left, R.id.pc_import_btn_login}, type = View.OnClickListener.class)
    private void onClick(View view) {
        switch (view.getId()) {
            case R.id.icon_left:// 返回
                finish();
                break;
            case R.id.pc_import_btn_login:// 扫一扫登录
                break;
        }
    }

    private void initTitle() {
        topName.setText(R.string.pc_import_tv_title);
        topDesc.setVisibility(View.GONE);
        leftIcon.setImageResource(R.mipmap.arrow_white_left);
        rightIcon.setVisibility(View.GONE);
    }

    private void initBGABanner() {
        List<BaseFragment> fragments = new ArrayList<>();

        PcImportFragment firstFragment = new PcImportFragment();
        firstFragment.mGuideNumber = PcImportFragment.GUIDE_NUMBER_FIRST;
        fragments.add(firstFragment);

        PcImportFragment secondFragment = new PcImportFragment();
        secondFragment.mGuideNumber = PcImportFragment.GUIDE_NUMBER_SECOND;
        fragments.add(secondFragment);

        PcImportFragment thirdFragment = new PcImportFragment();
        thirdFragment.mGuideNumber = PcImportFragment.GUIDE_NUMBER_THIRD;
        fragments.add(thirdFragment);

        BaseFraAdapter adapter = new BaseFraAdapter(getSupportFragmentManager(), fragments,
                new ArrayList<String>());
        mViewPager.setAdapter(adapter);
        mViewPager.setOnPageChangeListener(mOnPageChange);
        mViewPager.setOffscreenPageLimit(fragments.size());
    }

    ViewPager.OnPageChangeListener mOnPageChange = new ViewPager.OnPageChangeListener() {
        @Override
        public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

        }

        @Override
        public void onPageSelected(int position) {
            mGuideGp.check(position == 0 ? R.id.pc_import_rb1 : position == 1 ?
                    R.id.pc_import_rb2 : R.id.pc_import_rb3);
        }

        @Override
        public void onPageScrollStateChanged(int state) {

        }
    };
}
